package com.mcxx.modules.common.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.mcxx.modules.common.service.FundpayStatisticService;
import com.mcxx.modules.statistics.dto.FundPayCityStateDTO;
import com.mcxx.modules.statistics.dto.StatisticDTO;
import com.mcxx.modules.statistics.param.StatisticParam;
import com.mcxx.service.DefaultRestService;
import com.mcxx.util.Constant;
import com.mcxx.util.FileExportUtil;
import com.yinhai.ta404.component.audit.vo.ExcelInfo;
import com.yinhai.ta404.core.restservice.annotation.RestService;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import com.mcxx.modules.common.service.StatisticService;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@Validated
@Api("报表统计")
@RestService({"statistic/v2"})
public class StatisticController extends DefaultRestService {
    private static final Logger logger = LoggerFactory.getLogger(StatisticController.class);
    @Autowired
    private FundpayStatisticService fundpayStatisticService;

    @PostMapping("getFundpayCreate")
    @ApiOperation("名册生成情况统计")
    public void getFundpayCreate(StatisticParam param){
        logger.info("查询名册生成情况统计,条件是{}", param);

        List<FundPayCityStateDTO> list = fundpayStatisticService.getFundPayCreatedInfo(param,getCurUserAccount());
        setData(list);
        logger.info("查询名册生成情况统计,结果是{}", list);
    }

    @PostMapping({"downLoadFundpayCreate"})
    @ApiOperation("名册生成情况统计导出")
    public void downLoadFundpayCreate(HttpServletResponse response, @RequestBody StatisticParam param) throws IOException {
        ExcelInfo excelInfo = fundpayStatisticService.exportFundpayCreate(param,getCurUserAccount());
        if(null != excelInfo){
            FileExportUtil.exportFileResponse(response, excelInfo, getCurUserAccount().getAreaName());
//            ZipInfoUtil.exportZipResponse(response, excelInfo, this.getCurUserId());
        }
    }

    @PostMapping("citySubComprehensive")
    @ApiOperation("查询城市低保综合统计")
    public void citySubComprehensive(StatisticParam param){
        logger.info("查询城市低保综合统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticSubServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_DIBAO);
        setData(list);
        logger.info("查询城市低保综合统计,结果是{}", list);
    }

    @PostMapping("countrySubComprehensive")
    @ApiOperation("查询农村低保综合统计")
    public void countrySubComprehensive(StatisticParam param){
        logger.info("查询农村低保综合统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticSubServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_DIBAO);
        setData(list);
        logger.info("查询农村低保综合统计,结果是{}", list);
    }

    @PostMapping("citySubReveal")
    @ApiOperation("查询城市低保兜底脱贫统计")
    public void citySubReveal(StatisticParam param){
        logger.info("查询城市低保兜底脱贫统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticSubRevealServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_DIBAO);
        setData(list);
        logger.info("查询城市低保兜底脱贫统计,结果是{}", list);
    }

    @PostMapping("countrySubReveal")
    @ApiOperation("查询农村低保兜底脱贫统计")
    public void countrySubReveal(StatisticParam param){
        logger.info("查询农村低保兜底脱贫统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticSubRevealServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_DIBAO);
        setData(list);
        logger.info("查询农村低保兜底脱贫统计,结果是{}", list);
    }

    @PostMapping("citySubSummary")
    @ApiOperation("查询城市低保审批汇总表")
    public void citySubSummary(StatisticParam param){
        logger.info("查询城市低保审批汇总表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();

        StatisticService statisticService = SpringUtil.getBean("statSingleSummaryServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_DIBAO);
        setData(list);
        logger.info("查询城市低保审批汇总表,结果是{}", list);
    }

    @PostMapping("countrySubSummary")
    @ApiOperation("查询农村低保审批汇总表")
    public void countrySubSummary(StatisticParam param){
        logger.info("查询农村低保审批汇总表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();

        StatisticService statisticService = SpringUtil.getBean("statSingleSummaryServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_DIBAO);
        setData(list);
        logger.info("查询农村低保审批汇总表,结果是{}", list);
    }

    @PostMapping("cityPovertyComprehensive")
    @ApiOperation("查询城市特困综合统计")
    public void cityPovertyComprehensive(StatisticParam param){
        logger.info("查询城市特困综合统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticPovertyServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_TEKUN);
        setData(list);
        logger.info("查询城市特困综合统计,结果是{}", list);
    }

    @PostMapping("countryPovertyComprehensive")
    @ApiOperation("查询农村特困综合统计")
    public void countryPovertyComprehensive(StatisticParam param){
        logger.info("查询农村特困综合统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticPovertyServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_TEKUN);
        setData(list);
        logger.info("查询农村特困综合统计,结果是{}", list);
    }

    @PostMapping("cityPovertyReveal")
    @ApiOperation("查询城市特困兜底统计")
    public void cityPovertyReveal(StatisticParam param){
        logger.info("查询城市特困兜底统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticPovertyRevealServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_TEKUN);
        setData(list);
        logger.info("查询城市特困兜底统计,结果是{}", list);
    }

    @PostMapping("countryPovertyReveal")
    @ApiOperation("查询农村特困兜底统计")
    public void countryPovertyReveal(StatisticParam param){
        logger.info("查询农村特困兜底统计,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticPovertyRevealServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_TEKUN);
        setData(list);
        logger.info("查询农村特困兜底统计,结果是{}", list);
    }

    @PostMapping("cityPovertySummary")
    @ApiOperation("查询城市特困审批汇总表")
    public void cityPovertySummary(StatisticParam param){
        logger.info("查询城市特困审批汇总表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticPovertySummaryService");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_TEKUN);
        setData(list);
        logger.info("查询城市特困审批汇总表,结果是{}", list);
    }

    @PostMapping("countryPovertySummary")
    @ApiOperation("查询农村特困审批汇总表")
    public void countryPovertySummary(StatisticParam param){
        logger.info("查询农村特困审批汇总表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticPovertySummaryService");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_TEKUN);
        setData(list);
        logger.info("查询农村特困审批汇总表,结果是{}", list);
    }

    @PostMapping("temp")
    @ApiOperation("查询临时救助情况统计报表")
    public void temp(StatisticParam param){
        logger.info("查询临时救助情况统计报表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("statisticTempServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                    Constant.BusinessStandType.LINGSHI);
        setData(list);
        logger.info("查询临时救助情况统计报表,结果是{}", list);
    }

    @PostMapping("tempSummary")
    @ApiOperation("查询临时救助审批汇总表")
    public void tempSummary(StatisticParam param){
        logger.info("查询临时救助审批汇总表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("tempSummaryService");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_DIBAO);
        setData(list);
        logger.info("查询临时救助审批汇总表,结果是{}", list);
    }

    @PostMapping("cityPovertyFamilyDynamic")
    @ApiOperation("查询城市特困家庭动态变化表")
    public void cityPovertyFamilyDynamic(StatisticParam param){
        logger.info("查询城市特困家庭动态变化表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("cityPovertyFamilyDynamicServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_TEKUN);
        setData(list);
        logger.info("查询城市特困家庭动态变化表,结果是{}", list);
    }

    @PostMapping("countryPovertyFamilyDynamic")
    @ApiOperation("查询农村特困家庭动态变化表")
    public void countryPovertyFamilyDynamic(StatisticParam param){
        logger.info("查询农村特困家庭动态变化表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("cityPovertyFamilyDynamicServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_TEKUN);
        setData(list);
        logger.info("查询农村特困家庭动态变化表,结果是{}", list);
    }

    @PostMapping("citySubComprehensiveFamilyDynamic")
    @ApiOperation("查询城市低保家庭动态变化表")
    public void citySubComprehensiveFamilyDynamic(StatisticParam param){
        logger.info("查询城市低保家庭动态变化表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("subComprehensiveFamilyDynamicServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.CITY_DIBAO);
        setData(list);
        logger.info("查询城市低保家庭动态变化表,结果是{}", list);
    }

    @PostMapping("countrySubComprehensiveFamilyDynamic")
    @ApiOperation("查询农村低保家庭动态变化表")
    public void countrySubComprehensiveFamilyDynamic(StatisticParam param){
        logger.info("查询农村低保家庭动态变化表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("subComprehensiveFamilyDynamicServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessStandType.COUNTY_DIBAO);
        setData(list);
        logger.info("查询农村低保家庭动态变化表,结果是{}", list);
    }

    @PostMapping("dynamicFamilyWatch")
    @ApiOperation("家庭动态监测统计表")
    public void dynamicFamilyWatch(StatisticParam param){
        logger.info("查询家庭动态监测统计表,条件是{}", param);
        UserAccountVo accountVo = getCurUserAccount();
        StatisticService statisticService = SpringUtil.getBean("dynamicFamilyWatchServiceImpl");
        List<? extends StatisticDTO> list = statisticService.getStatistic(param, accountVo,
                Constant.BusinessCode.DISHOURU);
        setData(list);
        logger.info("查询家庭动态监测统计表,结果是{}", list);
    }
}
